﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PMS.Client.Entities;
using PMS.Client.IDAL;

namespace PMS.Client.DAL
{
    public class RoleAccess : WebAccess, IRoleAccess
    {
        public RoleAccess(GlobalValues globalValues) : base(globalValues)
        {
        }

        public string CheckRoleName(string roleName, int id)
        {
            string uri = $"/api/role/check/{id}/{roleName}";
            return this.Get(uri);
        }

        public string Delete(int id)
        {
            string uri = $"/api/role/delete/{id}";
            return this.Get(uri);
        }

        public string DeleteRoleUser(int rid, int uid)
        {
            string uri = $"/api/role/del_user/{rid}/{uid}";
            return this.Get(uri);
        }

        public string GetAllRoles(string key)
        {
            key = string.IsNullOrEmpty(key) ? "none" : key;
            string uri = $"/api/role/all/{key}";
            return this.Get(uri);
        }

        public string GetRoleByIds(string id_json)
        {
            string uri = "/api/role/list";

            StringContent content = new StringContent(id_json);
            content.Headers.ContentType =
                new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return this.Post(uri, content);
        }

        public string Update(string role)
        {
            string uri = "/api/role/update";

            StringContent content = new StringContent(role);
            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return this.Post(uri, content);
        }

        public string UpdateRoleMenus(string roleMenus_json)
        {
            string uri = "/api/role/rmenus";

            StringContent content = new StringContent(roleMenus_json);
            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return this.Post(uri, content);
        }

        public string UpdateRoleUsers(string roleUsers_json)
        {
            string uri = "/api/role/rusers";

            StringContent content = new StringContent(roleUsers_json);
            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return this.Post(uri, content);
        }
    }
}
